package model;
/**
 * No use of this class now, until the example is expanded into more powerful app
 */

import java.math.BigInteger;
import java.util.List;

public class UserNumber {
	
	/**
	 * For ANY values BigInteger is used
	 */
	private final BigInteger value;
	
	private List<BigInteger> primes;
	
	public UserNumber(BigInteger n){
		value = n;
	}
	
	public BigInteger get(){
		return value;
	}
	
	@Override 
	public int hashCode() {
		return 17 + value.hashCode() * 31;
	}
	
	@Override 
	public boolean equals(Object obj) {
		if (!(obj instanceof UserNumber)) return false;
		if (obj == this) return true;
		UserNumber oun = (UserNumber)obj;
		return value.equals(oun.value);
	}
	
	/**
	 * Associates the initial User Number with its decomposed primes
	 * @param primes
	 */
	public synchronized void setPrimes(List<BigInteger> primes){
		this.primes = primes;
	}
	
	
	/**
	 * Returns list of Primes pre-calculated by a Remote server
	 * @return <code>List of BigInteger</code>
	 */
	public synchronized List<BigInteger> getPrimes(){
		return primes;
	}
	
	@Override
	public String toString() {
		StringBuilder result = new StringBuilder(String.format("Number %s is a product of ", value.toString()));
		for (BigInteger bi : primes) {
			result.append(bi.toString() + ", ");
		}
		if (primes.size() > 0){
			result.delete(result.length() - 2, result.length());
		}
		return result.toString();
	}
}
